package assist.datastore.parser;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

import assist.domain.model.Game;

public class NHLGamesCSVParser extends NHLCSVParser<Game>
{

    private static final long serialVersionUID = 1L;
    private SimpleDateFormat df;
    public NHLGamesCSVParser(final File csvFile, Integer numRecs) throws IOException
    {
       super(csvFile, numRecs);
    }

    @Override
    protected Game parseObject(String[] tokens)
    {
        Game game = new Game();
        Integer year = new Integer(tokens[0].split("\\.")[0]);
        Integer gameId = new Integer(tokens[2].split("\\.")[0]);
        game.setId(year + "" + gameId);
        if (df == null) 
        {
            df = new SimpleDateFormat("MMM dd ''yy", Locale.US);
        }
        try
        {
            game.setDate(df.parse(tokens[3]));
//System.err.println("Date:" + game.getDate());            
        }
        catch (ParseException e)
        {
            // TODO Auto-generated catch block
            System.err.println(e + ":" +  e.getMessage());
        }
        game.setHomeTeamId(tokens[6]);
        game.setVisitorTeamId(tokens[4]);
        
        
        return game;
    }

}
